<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="/WEB-INF/tlds/authorizetag.tld" prefix="px"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>门店操作</title>
<link href="/admin/public/bootstrap.min.css" title="" rel="stylesheet" />
<link href="/admin/font-awesome/css/font-awesome.min.css"
	rel="stylesheet">
<link href="/admin/public/animate.css" rel="stylesheet">
<link rel="stylesheet" href="/admin/public/inspinia.css" />
<link rel="stylesheet" href="/admin/css/pop-up.css" />
<link rel="stylesheet" href="/admin/css/plugins/toastr/toastr.min.css" />
<link rel="stylesheet" type="text/css"
	href="${request.getContext }/admin/css/xcConfirm.css" />


<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
	<script src="/admin/public/html5shiv.min.js"></script>
	<script src="/admin/public/respond.min.js"></script>
<![endif]-->
<style type="text/css">
.img{
	height: 130px;
	width:180px;
}
</style>
</head>
<body>
	<div id="wrapper" class="container">
		<div class="wrapper wrapper-content">
			<div class="right_box">
				<div style="border: none; box-shadow: none;" class="right_one row">
					<div class="col-md-12 col-sm-12 col-xs-12" style="float: left;">
						<!-- 添加 -->
						<form class="form-horizontal" method="post" id="addClient"
							novalidate="novalidate" enctype="multipart/form-data">
							<div class="form-group">
								<label class="col-lg-2 control-label"><span style="color:red;">*</span>选择门店:</label>
								<div class="col-lg-6">
									<select class="select2_demo_1 form-control" name="shopId"
									id="shopId">
									<c:forEach items="${shopNameList }" var="item">
										<option value="${item.shopId }" <c:if test="${shopId eq item.shopId }">selected="selected" </c:if>>${item.shopName }</option>
									</c:forEach>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label"><span style="color:red;">*</span>课程类型:</label>
								<div class="col-lg-6">
									<select class="select2_demo_1 form-control" name="courseType"
									id="courseType">
										<option value="0">团课</option>
										<option value="2">训练营</option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label"><span style="color:red;">*</span>二维码图片:</label>
								<div class="col-lg-6">
									<input type="file" class="form-control" id="picUrl"
										name="picUrl"  onchange="preview(this,1)">
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label"></label>
								<div class="col-lg-6">
									<span style="color:red;">建议图片尺寸：300*300</span>
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label"></label>
								<div class="col-lg-6">
									<div id="preview1"></div>
								</div>
							</div>
							<px:authorize setting="二维码-添加二维码">
								<input type="button" onclick="add();" style="display: none;"
									id="tijiao" value="添加" />
							</px:authorize>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script src="/admin/public/jquery-1.11.3.js"></script>
	<script src="/admin/public/bootstrap.min.js" type="text/javascript"></script>
	<script src="${request.getContext }/admin/js/xcConfirm.js"
		type="text/javascript" charset="utf-8"></script>
	<script src="/admin/js/plugins/toastr/toastr.min.js"></script>
	<script src="/admin/js/new_page.js"></script>
	<!-- ajax上传文件要的包 -->
	<script src="/admin/js/jquery.form.min.js"></script>
	<script type="text/javascript">
		function preview(file, i) {
			var prevDiv = document.getElementById('preview' + i);
			if (file.files && file.files[0]) {
				var reader = new FileReader();
				reader.onload = function(evt) {
					prevDiv.innerHTML = '<img class="img" src="' + evt.target.result + '" />';
				}
				reader.readAsDataURL(file.files[0]);
			} else {
				prevDiv.innerHTML = '<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
			}
		}
	</script>
	<script type="text/javascript">
		function check() {
			var shopId = $("#shopId").val();
			var courseType = $("#courseType").val();
			var picUrl = $("#picUrl").val();
			if (shopId == null || shopId == '') {
				alertNew("请选择门店！", false);
				return false;
			}
			if (courseType == null || courseType == '') {
				alertNew("请选择课程类型！", false);
				return false;
			}
			if (picUrl == null || picUrl == '') {
				alertNew("二维码图片不得为空", false);
				return false;
			}
			return true;

		}
		//添加二维码
		function add() {
			if (check()) {
				$('#addClient').ajaxSubmit({
					type : "post",
					data : $("#addClient").serialize(),
					dataType : "json",
					enctype:"multipart/form-data",
					url : "/admin/QRcode/addQR",
					success : function(data) {
						if (data.success) {
							window.wxc.xcConfirm(data.msg, window.wxc.xcConfirm.typeEnum.info,{onOk:function(){ 
								$('#ifr', window.parent.document).attr('src',
								'/admin/QRcode/list');
					  		}})
						}else{
							alertNew(data.msg, false);
						}
					},
					error : function(data) {
						alert("很抱歉，未知的错误发生了！");
					}
				});
			}
		}
	</script>

</body>
</html>
